package immutable;

import java.util.Iterator;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) {
        //创建不可变集合
        //通过集合的of方法进行创建
        List<String> list = List.of("jack", "tom");
        //1.进行遍历
        for (String s : list) {
            System.out.println(s);
        }
        //2.
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //3.
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        //不可添加和修改
        //list.add("tom");

    }
}
